<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col :span="mainwidth" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

          <el-form-item label="时间类型" prop="status">
            <el-select
              v-model="queryParams.timetype"
              placeholder="时间类型"
              clearable
              size="small"
              style="width: 130px"
            >
              <el-option
                v-for="dict in timetypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="selTime"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 260px"
              align="right">
            </el-date-picker>
          </el-form-item>

          <el-form-item label="所属销售">
            <el-select v-model="queryParams.sales_idArr" multiple clearable  :disabled="clearableBool" placeholder="请选择">
              <el-option
                v-for="item in SalesOption"
                :key="item.user_id"
                :label="item.nick_name"
                :value="item.user_id"
              ></el-option>
            </el-select>
          </el-form-item>

        </el-form>

        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom: -10px;line-height:35px">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-input
                v-model="queryParams.value"
                placeholder="查询值"
                clearable
                size="small"
                style="width: 350px"
                @keyup.enter.native="handleQuery"
              >
                <el-select
                  v-model="queryParams.type"
                  placeholder="查询条件"
                  clearable
                  slot="prepend"
                  style="width: 110px;background-color: transparent;color: black;"
                >
                  <el-option
                    v-for="dict in typeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-input>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="签收状态" style="margin-bottom: 10px;line-height:35px">
                <el-select v-model="queryParams.EIY_Signing_Status" multiple clearable placeholder="请选择">
                  <el-option
                    v-for="dict in ExpressInquiry_SignForOption"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="快递评价" style="margin-bottom: 10px;line-height:35px">
                <el-select v-model="queryParams.EIY_Evaluation_Status" multiple clearable placeholder="请选择">
                  <el-option
                    v-for="dict in ExpressInquiry_EvaluationOption"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" v-hasPermi="['yunze:ExpressInquiry:list']"
                           @queryTable="getList"
                           :columns="columns"></right-toolbar>
          </el-row>
        </el-form>



        <el-table v-loading="loading" :data="DataList" >
          <el-table-column :label="columns[0].label" align="center" prop="EIY_ID" v-if="columns[0].visible"/>
          <el-table-column :label="columns[1].label" align="center" prop="EIY_Ship_Time" v-if="columns[1].visible"/>
          <el-table-column :label="columns[2].label" align="center" prop="SAN_CoName" v-if="columns[2].visible"/>
          <el-table-column :label="columns[3].label" align="center" prop="SAN_Recipient_Name"
                           v-if="columns[3].visible"/>
          <el-table-column :label="columns[4].label" align="center" prop="EIY_Express_Delivery"
                           v-if="columns[4].visible">
            <template slot-scope="scope">
              {{tools.getkeyValue(CourierCompanyOptions,scope.row.EIY_Express_Delivery,"EDY_ID","EDY_Name")}}
            </template>
          </el-table-column>

          <el-table-column :label="columns[5].label" align="center" prop="EIY_Tracking_Number"
                           v-if="columns[5].visible"/>
          <el-table-column :label="columns[6].label" align="center" prop="SAN_Sender_Name" v-if="columns[6].visible"/>

          <el-table-column :label="columns[7].label" align="center" prop="EIY_Signing_Status" v-if="columns[7].visible">
            <template slot-scope="scope">
              <span :class="getColor(scope.row.EIY_Signing_Status)">{{tools.getDkeyValue(ExpressInquiry_SignForOption,scope.row.EIY_Signing_Status)}}</span>
            </template>
          </el-table-column>
          <el-table-column :label="columns[8].label" align="center" prop="EIY_Time" v-if="columns[8].visible"/>
          <el-table-column :label="columns[9].label" align="center" prop="EIY_Evaluation_Status"
                           v-if="columns[9].visible">
            <template slot-scope="scope">
              <span :class="getColor(scope.row.EIY_Evaluation_Status)">{{tools.getDkeyValue(ExpressInquiry_EvaluationOption,scope.row.EIY_Evaluation_Status)}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">

              <el-dropdown>
                <el-button type="primary" size="small">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-hasPermi="['yunze:ExpressInquiry:upd']"
                                    @click.native="handleUpdate(scope.row,'Edit')">修改
                  </el-dropdown-item>
                  <el-dropdown-item v-hasPermi="['yunze:ExpressInquiry:find']"
                                    @click.native="handleUpdate(scope.row,'Find')">详情
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>

              <!-- <el-button
                 size="mini"
                 type="text"
                 icon="el-icon-edit"
                 @click="onPreview(scope.row)"
               >图片查看
               </el-button>-->

            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>


    <!--  快递编辑 -->
    <el-drawer
      :with-header="false"
      :visible.sync="show_ds_Register"
      :close-on-click-modal="false"
      size="90%">
      <el-scrollbar style="height:1000px;min-height: 100%;">
        <ExpressInquiryEdit  ref="expressInquiryEdit"
                          :DeliveryMethodOption="DeliveryMethodOption"
                          :ShippingMethodOption="ShippingMethodOption"
                          :CourierCompanyOptions="CourierCompanyOptions"
                          :form="form"
                          :window="window"
                          :CustomerAdd="CustomerAdd"
                          :CustomerEdie="CustomerEdie"
                          :show_ds_Register="show_ds_Register"
                           :execute="execute"
                          @SetObj="SetObj"
                          :SubUpd="SubUpd"
                         :ExpressInquiry_SignForOption="ExpressInquiry_SignForOption"
                         :ExpressInquiry_EvaluationOption="ExpressInquiry_EvaluationOption"
        />




        <div style="height: 2000px;"></div>
      </el-scrollbar>

    </el-drawer>



  </div>
</template>


<script>
  import {getList,UpdInfo} from "@/api/yunze/FHGL/ExpressInquiry";
  import tools from "@/utils/yunze/tools";
  import {ExpressSelDate} from "@/api/yunze/FHGL/FhglExpressDelivery";
  import ExpressInquiryEdit from './ExpressInquiryEdit';
  import {findSalesPartner} from "@/api/yunze/XSGL/customer/customer";


  export default {
    name: "ExpressInquiry",
    components: {
      ExpressInquiryEdit,
    },
    data() {
      return {

        SalesOption: [],//销售
        clearableBool:false,//所属销售是否 禁止选择

        DeliveryTypeOption: [], //数据字典 发货类型
        DeliveryMethodOption: [], //数据字典 发货方式
        ShippingMethodOption: [],//数据字典 运费方式
        CourierCompanyOptions: [],//数据字典 快递公司信息
        timetypeOptions: [],// 时间查询类型 数据字典
        ExpressInquiry_SignForOption: [],//加载 快递签收状态
        ExpressInquiry_EvaluationOption: [], //加载 快递评价

        selTime: '',//时间选择
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },

        Editexecute: true,//发货申请 编辑加载是否 已执行
        execute: false,//加载是否 已执行

        //保存 编辑 按钮
        CustomerAdd: false,
        CustomerEdie: false,
        tools: tools,
        show_ds_Register: false,//详情查看 发货登记
        mainwidth: 24,//宽度
        loading: true,// 遮罩层
        multiple: true,// 非多个禁用
        showSearch: false,// 显示搜索条件
        total: 0,// 总条数
        DataList: [],//主界面数据
        typeOptions: [],//时间条件 类型
        window: window,
        // 表单参数
        form: {
          EIY_ID: null,
          EIY_Signing_Status: null,
          EIY_Time: null,
          EIY_Evaluation_Status: null,
          EIY_Remarks: null,
          EIY_SANID: null,
          EIY_ShiptyID: '1',
          EIY_FpayType: '1',
          EIY_Tracking_Number: null,
          EIY_Express_Delivery: null,
          EIY_Delivery_Person: null,
          EIY_Ship_Time: tools.gitData(),
          SAN_CoName: null,
          SAN_Recipient_Name: null,
          SAN_Sender_Name: null,
          SAN_Time: null,
        },
        // 查询参数
        queryParams: {
          EIY_Signing_Status: ['1'],
          EIY_Evaluation_Status: ['1'],
          pageNum: 1,
          pageSize: 10,
          type: null,
          value: null,
          sales_idArr:[],
        },
        // 列信息
        columns: [
          {key: 0, label: `快递编号`, visible: true},
          {key: 1, label: `发货日期`, visible: true},
          {key: 2, label: `企业名称`, visible: true},
          {key: 3, label: `收件人`, visible: true},
          {key: 4, label: `快递公司`, visible: true},
          {key: 5, label: `单号`, visible: true},
          {key: 6, label: `发件人`, visible: true},
          {key: 7, label: `签收状态`, visible: true},
          {key: 8, label: `收件日期`, visible: true},
          {key: 9, label: `快递评价`, visible: true},
        ],
        // 表单校验
        rules: {}
      };
    },
    created() {




      //加载 查询条件
      if (window['ExpressInquiry_selType'] != undefined && window['ExpressInquiry_selType'] != null && window['ExpressInquiry_selType'] != '') {
        this.typeOptions = window['ExpressInquiry_selType'];
      } else {
        this.getDicts("yunze_ExpressInquiry_selType").then(response => {
          window['ExpressInquiry_selType'] = response.data;
          this.typeOptions = window['ExpressInquiry_selType'];
        });
      }

      //加载 查询时间类型 条件
      if (window['ExpressInquiry_timetype'] != undefined && window['ExpressInquiry_timetype'] != null && window['ExpressInquiry_timetype'] != '') {
        this.timetypeOptions = window['ExpressInquiry_timetype'];
      } else {
        this.getDicts("yunze_ExpressInquiry_timetype").then(response => {
          window['ExpressInquiry_timetype'] = response.data;
          this.timetypeOptions = window['ExpressInquiry_timetype'];
        });
      }


      //加载 快递签收状态
      if (window['ExpressInquiry_SignForOption'] != undefined && window['ExpressInquiry_SignForOption'] != null && window['ExpressInquiry_SignForOption'] != '') {
        this.ExpressInquiry_SignForOption = window['ExpressInquiry_SignForOption'];
      } else {
        this.getDicts("yunze_ExpressInquiry_SignFor").then(response => {
          window['ExpressInquiry_SignForOption'] = response.data;
          this.ExpressInquiry_SignForOption = window['ExpressInquiry_SignForOption'];
        });
      }

      //加载 快递评价
      if (window['ExpressInquiry_EvaluationOption'] != undefined && window['ExpressInquiry_EvaluationOption'] != null && window['ExpressInquiry_EvaluationOption'] != '') {
        this.ExpressInquiry_EvaluationOption = window['ExpressInquiry_EvaluationOption'];
      } else {
        this.getDicts("yunze_ExpressInquiry_Evaluation").then(response => {
          window['ExpressInquiry_EvaluationOption'] = response.data;
          this.ExpressInquiry_EvaluationOption = window['ExpressInquiry_EvaluationOption'];
        });
      }





      //加载 发货类型
      if (window['DeliveryTypeOption'] != undefined && window['DeliveryTypeOption'] != null && window['DeliveryTypeOption'] != '') {
        this.DeliveryTypeOption = window['DeliveryTypeOption'];
      } else {
        this.getDicts("Delivery_type").then(response => {
          window['DeliveryTypeOption'] = response.data;
          this.DeliveryTypeOption = window['DeliveryTypeOption'];
        });
      }




      //加载 发货方式
      if (window['DeliveryMethodOption'] != undefined && window['DeliveryMethodOption'] != null && window['DeliveryMethodOption'] != '') {
        this.DeliveryMethodOption = window['DeliveryMethodOption'];
      } else {
        this.getDicts("Delivery_method").then(response => {
          window['DeliveryMethodOption'] = response.data;
          this.DeliveryMethodOption = window['DeliveryMethodOption'];
        });
      }

      //加载 运费方式
      if (window['ShippingMethodOption'] != undefined && window['ShippingMethodOption'] != null && window['ShippingMethodOption'] != '') {
        this.ShippingMethodOption = window['ShippingMethodOption'];
      } else {
        this.getDicts("Shipping_method").then(response => {
          window['ShippingMethodOption'] = response.data;
          this.ShippingMethodOption = window['ShippingMethodOption'];
        });
      }

      //加载 快递公司信息
      if (window['CourierCompanyOptions'] != undefined && window['CourierCompanyOptions'] != null && window['CourierCompanyOptions'] != '') {
        this.CourierCompanyOptions = window['CourierCompanyOptions'];
        this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
      } else {
        ExpressSelDate(tools.encrypt(JSON.stringify({}))).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          window['CourierCompanyOptions'] = jsonobj.Data;
          this.CourierCompanyOptions = window['CourierCompanyOptions'];
          this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
        });
      }


      //加载  销售
      if(window['SalesOption']!=undefined &&  window['SalesOption']!=null && window['SalesOption']!=''){
        this.SalesOption = window['SalesOption'];
        this.Sales_execution();//过滤 Btns 权限 销售尽可看自身数据
      }else{
        let map = {};
        map.isSales = 1;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        findSalesPartner(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          if (jsonobj.code == 200) {
            window['SalesOption'] = jsonobj.Data;
            this.SalesOption = window['SalesOption'];
            //console.log(this.SalesOption)
            this.Sales_execution();//过滤 Btns 权限 销售尽可看自身数据
          }else{
            this.msgError(jsonobj.msg);
          }
        })
      }

      //条件查询 默认选择第一个
      this.queryParams.type = '1';

    },
    methods: {

      //销售执行函数 清除 所属销售其他选项只留自己的
      Sales_execution(){
        let username = tools.getCookie("username");
        //console.log(username)
        if(username!='admin'){
          //console.log(this.SalesOption)
          if(this.SalesOption!=null && this.SalesOption.length>0){
            let SalesOption = JSON.parse(JSON.stringify(this.SalesOption));
            this.SalesOption = [];
            for (let i = 0; i < SalesOption.length; i++) {
              let Obj = SalesOption[i];
              let arr = [];
              if(Obj.Btns!=null && Obj.Btns.indexOf(',')!=-1){
                arr = Obj.Btns.split(",");
              }else{
                arr = [Obj.Btns]
              }
              if (Obj.user_name == username) {
                if(tools.VerificationValIsArray(arr,"yunze:sys:Sales")){
                  this.SalesOption.push(Obj);
                  this.queryParams.sales_idArr = [Obj.user_id];
                  this.clearableBool = true;
                }else{
                  this.SalesOption = SalesOption;
                }
                break;
              }
            }
          }
          this.getList();
        }else{
          this.getList();
        }
      },



      //设置数据
      SetObj(Key, obj) {
        //console.log(obj);
        switch (Key) {
          case 'SetEditexecute':
            this.Editexecute = obj;//设置 发货申请 编辑  是否已经加载 [提供给子组件使用]
            break;
          case 'Setform':
            this.form = obj;// 设置 form
            break;
          case 'SetExecute':
            this.execute = obj;// 加载是否 已执行
            break;
          case 'Setshow_ds_Register':
            this.show_ds_Register = obj;// 加载是否 已执行
            break;
        }
      },








      //获取对应 class 颜色
      getColor(key) {
        var class_color = "";
        switch (key) {
          case 1:
            class_color = 'my_cloor_red';
            break;
          case 2:
            class_color = 'my_cloor_blue';
            break;
          case 3:
            class_color = 'my_cloor_Orange';
            break;
          case 4:
            class_color = 'my_cloor_Green';
            break;
          default:
            class_color = 'my_cloor_black';
            break;
        }
        return class_color;
      },


      /*获取查询参数*/
      getParams() {
        if (tools.Is_null(this.queryParams.timetype) && this.selTime != null) {
          this.queryParams.staTime = this.selTime[0];
          this.queryParams.endTime = this.selTime[1];
        }
        //console.log(this.queryParams);
      },
      /** 查询 */
      getList() {
        this.loading = true;
        this.getParams();
        this.queryParams.page = 1;
        let Pwd_Str = tools.encrypt(JSON.stringify(this.queryParams));
        getList(Pwd_Str).then(response => {
            let jsonobj = JSON.parse(tools.Decrypt(response));
            if (jsonobj.code == 200) {
              //console.log(jsonobj)
              this.DataList = jsonobj.Data.Data;
              this.total = jsonobj.Data.Pu.rowCount;
            } else {
              this.msgError(jsonobj.msg);
            }
            this.loading = false;
          }
        );
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams = {};
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.selTime = null;
        this.handleQuery();
      },



      /** 表格 按钮操作 */
      handleUpdate(row, Operate) {
        this.form.EIY_ID = row.EIY_ID;//赋值 合同编号
        if (Operate == "Edit") {//载入发货 申请
          this.execute = false;//加载是否 已执行
          this.CustomerAdd = false;
          this.CustomerEdie = true;
        } else if (Operate == "Find") {
          this.execute = false;//加载是否 已执行
          this.CustomerAdd = false;
          this.CustomerEdie = false;
        }
        this.show_ds_Register = true;
      },




      SubUpd(map) {
        //console.log(map);
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        UpdInfo(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.msgSuccess(jsonobj.msg);
            this.show_ds_Register = false;
            //更新数据
            this.queryParams.page = 1;
            this.getList();
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })

      },


    }
  };
</script>


<style scoped>
  .my_cloor_red {
    background-color: #e64242;
    color: white;
  }

  .my_cloor_blue {
    background-color: #1682e6;
    color: white;
  }

  .my_cloor_Orange {
    background-color: #303133;
    color: white;
  }

  .my_cloor_Green {
    background-color: #5fb878;
    color: white;
  }

  .my_cloor_black {
    background-color: #303133;
    color: white;
  }

</style>


